//
//  QandACell.m
//  New
//
//  Created by 才诗琦 on 16/1/21.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "QandACell.h"

@implementation QandACell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imagView = [[UIImageView alloc] init];
        _imagView.layer.cornerRadius = 5;
        _imagView.clipsToBounds = YES;
        [self.contentView addSubview:_imagView];
        [_imagView release];
        
        //用户头像
        self.userView = [[UIImageView alloc] init];
        _userView.layer.cornerRadius = 20;
        _userView.layer.borderColor = [UIColor whiteColor].CGColor;
        _userView.layer.borderWidth = 2;
        _userView.clipsToBounds = YES;
        [self.imagView addSubview:_userView];
        [_userView release];
        
        //描述
        self.aliasLabel = [[UILabel alloc] init];
        _aliasLabel.numberOfLines = 0;
        [self.contentView addSubview: _aliasLabel];
        [_aliasLabel release];
        
        //作者名
        self.nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor whiteColor];
        [self.imagView addSubview:_nameLabel];
        [_nameLabel release];
        //类型
        self.classificationLabel = [[UILabel alloc] init];
        _classificationLabel.textColor = [UIColor blueColor];
        _classificationLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_classificationLabel];
        [_classificationLabel release];
        
        //评论数
        self.concernCountLabel = [[UILabel alloc] init];
        _concernCountLabel.textColor = [UIColor grayColor];
        _concernCountLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_concernCountLabel];
        [_concernCountLabel release];
        
       //关注
        self.guanzhu = [[UILabel alloc] init];
        _guanzhu.text = @"关注|";
        _guanzhu.textColor = [UIColor grayColor];
        _guanzhu.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_guanzhu];
        [_guanzhu release];
        
        //进行
        self.jinxing = [[UILabel alloc] init];
        _jinxing.text = @"|进行中";
        _jinxing.textColor = [UIColor grayColor];
        _jinxing.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_jinxing];
        [_jinxing release];
        
        
        
        
    }
    
    return self;
    
}

- (void)layoutSubviews
{
    
    [super layoutSubviews];
    
    self.imagView.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, 170);
    self.userView.frame =CGRectMake(10, 100, 40, 40);
    self.nameLabel.frame = CGRectMake(60, 100, 80, 40);
    CGFloat h = [[self class] heightWithText:_aliasLabel.text];
    self.aliasLabel.frame = CGRectMake(10, 170, self.contentView.frame.size.width - 20, h);
    
    self.concernCountLabel.frame = CGRectMake(10, h + 160, 60, 30);
    
    self.guanzhu.frame = CGRectMake(70, h + 160, 50, 30);
    self.classificationLabel.frame = CGRectMake(120, h + 160, 40, 30);
    
    self.jinxing.frame = CGRectMake(160, h + 160, 60, 30);
    
}

+(CGFloat)heightWithText:(NSString *)str
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(155, 1000);
    CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
